<?php
namespace Sys\Controller;
use Sys\Controller\BasetwoController;

class StudentController extends BasetwoController{

    public function index(){

        $User = M('students');//实例化User对象
        //进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用$_GET[p]获取
        $list = $User->page($_GET['p'],'10')->select();
        $this->assign('navs',$list);// 赋值数据集
        $count= $User->count();// 查询满足要求的总记录数
        $Page= new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page -> setConfig('header','<span class="rows">共<b>%TOTAL_ROW%</b>条记录 第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</span>');
        $Page -> setConfig('prev', '上一页');
        $Page -> setConfig('next','下一页');
        $Page -> setConfig('last','末页');
        $Page -> setConfig('first','首页');
        $Page -> setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        $show= $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }


    //删除学生
    public function doDelStudent(){
        $where['student_id']= I('post.ids');
        $res= M('students')->field('lg_photo')->where($where)->find();
        /*unlink($res);*/

         unlink('.'.$res['lg_photo']);
        M('students')->delete($where);
    }

    //修改学生
    public function doEditStudent(){
        $this-> phono();
        $res=D('students');
        if ($res->create()){
            $res->save();
            header('location:index');
        }else{
            echo '修改失败';
        }
    }
    //精确修改
    public function EditStudent(){

        $where['student_id']=I('GET.student_id');
        $user = M('students')->where($where)->select();
        $this->assign('user',$user);
        $this->display();
    }
    //添加学生
    public function phono(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize= 3145728*1024 ;// 设置附件上传大小
        $upload->exts= array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->savePath= '/'; // 设置附件上传目录
        $info= $upload->upload();
        $_POST['lg_photo'] = '/Uploads'.$info['photo']['savepath'].$info['photo']['savename'];
    }

    public function doAddStudent(){
        $this-> phono();

        M('students')->create();
        if(M('students')->add()){
            $a=U('index');
            header("location:{$a}");

        };
    }
}